package com.xuecheng.manage_cms.controller;

import com.xuecheng.api.cms.CmsTemplateControllerApi;
import com.xuecheng.framework.domain.cms.CmsTemplate;
import com.xuecheng.framework.domain.cms.request.QueryPageResult;
import com.xuecheng.framework.domain.cms.response.CmsPageResult;
import com.xuecheng.framework.domain.cms.response.CmsTemplateResult;
import com.xuecheng.framework.model.response.QueryResponseResult;
import com.xuecheng.framework.model.response.ResponseResult;
import com.xuecheng.manage_cms.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/cms/template")
public class CmsTemplateController implements CmsTemplateControllerApi {

    @Autowired
    private PageService pageService;

    //查询模板列表
    @Override
    @GetMapping("/list/{page}/{size}")
    public QueryResponseResult findList(@PathVariable("page") int page, @PathVariable("size") int size, QueryPageResult queryPageResult) {
        return pageService.findTemplateList(page,size,queryPageResult);
    }

    @Override
    @PostMapping("/add")
    public CmsTemplateResult add(@RequestBody CmsTemplate cmsTemplate) {
        return pageService.add(cmsTemplate);
    }

    @Override
    @PutMapping("/edit/{id}")
    public CmsTemplateResult update(@PathVariable("id") String id,@RequestBody CmsTemplate cmsTemplate) {
        return pageService.edit(id,cmsTemplate);
    }

    @GetMapping("/get/{id}")
    public CmsTemplate get(@PathVariable("id") String templateId){
       return pageService.findTemplateById(templateId);
    }


    @DeleteMapping("/del/{id}")
    public ResponseResult del(@PathVariable("id") String  id){
        return pageService.delTemplate(id);
    }
}
